package com.ygqh.baby.controller.admin;

import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ygqh.baby.ao.CommissionStatus;
import com.ygqh.baby.ao.Message;
import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.po.YgCommission;
import com.ygqh.baby.po.YgCommissionDetail;
import com.ygqh.baby.po.YgUserBank;
import com.ygqh.baby.service.YgCommissionDetailService;
import com.ygqh.baby.service.YgCommissionService;

@Controller
@RequestMapping("/admin/finance")
public class FinanceController extends BaseController<Object, java.lang.Long> {

	@Autowired
	private YgCommissionService ygCommissionService;
	@Autowired
	private YgCommissionDetailService ygCommissionDetailService;

	@RequestMapping("getUserAccount")
	@ResponseBody
	public YgUserBank addCoupon(Long userId) {
		return ygCommissionService.findUserBank(userId);

	}

	@RequestMapping("updateCash")
	@ResponseBody
	public Message updateCash(Long id, CommissionStatus status, String remark) {
		YgCommission ygCommission = new YgCommission();
		ygCommission.setId(id);
		ygCommission.setCommissionStatus(status);
		ygCommission.setCheckBy(getSession().getTrueName());
		ygCommission.setCheckTime(new Date());
		ygCommission.setRemark(remark);
		return ygCommissionService.updateWithdrawStatus(id, status, remark) == 1 ? SUCCESS_MESSAGE : ERROR_MESSAGE;

	}

	@RequestMapping("searchCash")
	@ResponseBody
	public Map<String, Object> searchCash(QueryInfo queryInfo, String userName, CommissionStatus status, String q) {
		ResultSet<YgCommission> result = ygCommissionService.search(queryInfo, userName, status, q);
		return result.toDatatables(null);
	}

	@RequestMapping("searchCommissionDetail")
	@ResponseBody
	public Map<String, Object> searchCommissionDetail(QueryInfo queryInfo,Long commissionId) {
		ResultSet<YgCommissionDetail> result = ygCommissionDetailService.search(queryInfo, commissionId,null);
		return result.toDatatables(null);
	}
}
